package com.hdjk.view.callback;

import com.hdjk.view.entity.FundEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class FundListCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg=super.parseNetworkResponse(response, i);
        JSONObject object= (JSONObject) msg.getData();
        List<FundEntity> list = new ArrayList<>();
        if (object!=null) {
            if (!object.isNull("data")) {
                JSONArray array = object.getJSONArray("data");
                if (array != null && array.length() > 0) {
                    for (int j = 0; j < array.length(); j++) {
                        JSONObject jsonObject = array.getJSONObject(j);
                        FundEntity entity = new FundEntity();
                        if (!jsonObject.isNull("fundCode")) {
                            entity.setFundCode(jsonObject.getString("fundCode"));
                        }
                        if (!jsonObject.isNull("fundName")) {
                            entity.setFundName(jsonObject.getString("fundName"));
                        }
                        if (!jsonObject.isNull("fundFullName")) {
                            entity.setFundFullName(jsonObject.getString("fundFullName"));
                        }
                        if (!jsonObject.isNull("fundType")) {
                            entity.setFundType(jsonObject.getString("fundType"));
                        }
                        if (!jsonObject.isNull("fundStatus")) {
                            entity.setFundStatus(jsonObject.getString("fundStatus"));
                        }
                        if (!jsonObject.isNull("nav")) {
                            double l = jsonObject.getDouble("nav");
                            BigDecimal b = new BigDecimal(l);
                            entity.setNav(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("fundHouse")) {
                            entity.setFundHouse(jsonObject.getString("fundHouse"));
                        }
                        if (!jsonObject.isNull("fundHouseCode")) {
                            entity.setFundHouseCode(jsonObject.getString("fundHouseCode"));
                        }
                        if (!jsonObject.isNull("accumulateNav")) {
                            double l = jsonObject.getDouble("accumulateNav");
                            BigDecimal b = new BigDecimal(l);
                            entity.setAccumulateNav(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("day1Performance")) {
                            double l = jsonObject.getDouble("day1Performance");
                            BigDecimal b = new BigDecimal(l);
                            entity.setDay1Performance(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("navDate")) {
                            entity.setNavDate(jsonObject.getString("navDate"));
                        }
                        if (!jsonObject.isNull("earningsPer10000")) {
                            double l = jsonObject.getDouble("earningsPer10000");
                            BigDecimal b = new BigDecimal(l);
                            entity.setEarningsPer10000(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("sevenDaysAnnualizedYield")) {
                            double l = jsonObject.getDouble("sevenDaysAnnualizedYield");
                            BigDecimal b = new BigDecimal(l);
                            entity.setSevenDaysAnnualizedYield(b.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("isBuyEnable")) {
                            entity.setIsBuyEnable(jsonObject.getString("isBuyEnable"));
                        }
                        if (!jsonObject.isNull("isQDII")) {
                            entity.setIsQDII(jsonObject.getString("isQDII"));
                        }
                        if (!jsonObject.isNull("isMMFund")) {
                            entity.setIsMMFund(jsonObject.getString("isMMFund"));
                        }
                        if (!jsonObject.isNull("isRecommended")) {
                            entity.setIsRecommended(jsonObject.getString("isRecommended"));
                        }
                        if (!jsonObject.isNull("month1")) {
                            entity.setMonth1(jsonObject.getString("month1"));
                        }
                        if (!jsonObject.isNull("month3")) {
                            entity.setMonth3(jsonObject.getString("month3"));
                        }
                        if (!jsonObject.isNull("month6")) {
                            entity.setMonth6(jsonObject.getString("month6"));
                        }
                        if (!jsonObject.isNull("year1")) {
                            entity.setYear1(jsonObject.getString("year1"));
                        }
                        if (!jsonObject.isNull("year3")) {
                            entity.setYear3(jsonObject.getString("year3"));
                        }
                        if (!jsonObject.isNull("year5")) {
                            entity.setYear5(jsonObject.getString("year5"));
                        }
                        if (!jsonObject.isNull("sinceLaunch")) {
                            entity.setSinceLaunch(jsonObject.getString("sinceLaunch"));
                        }
                        if (!jsonObject.isNull("specializeSector")) {
                            entity.setSpecializeSector(jsonObject.getString("specializeSector"));
                        }
                        if (!jsonObject.isNull("geographicalSector")) {
                            entity.setGeographicalSector(jsonObject.getString("geographicalSector"));
                        }
                        if (!jsonObject.isNull("riskRate")) {
                            entity.setRiskRate(jsonObject.getString("riskRate"));
                        }
                        if (!jsonObject.isNull("fundSize")) {
                            entity.setFundSize(jsonObject.getString("fundSize"));
                        }
                        if (!jsonObject.isNull("chargeMode")) {
                            entity.setChargeMode(jsonObject.getString("chargeMode"));
                        }
                        if (!jsonObject.isNull("currency")) {
                            entity.setCurrency(jsonObject.getString("currency"));
                        }
                        if (!jsonObject.isNull("defaultDividendInstruction")) {
                            entity.setDefaultDividendInstruction(jsonObject.getString("defaultDividendInstruction"));
                        }
                        if (!jsonObject.isNull("dividendUpdateEnable")) {
                            entity.setDividendUpdateEnable(jsonObject.getString("dividendUpdateEnable"));
                        }
                        if (!jsonObject.isNull("fundCustodian")) {
                            entity.setFundCustodian(jsonObject.getString("fundCustodian"));
                        }
                        if (!jsonObject.isNull("launchDate")) {
                            entity.setLaunchDate(jsonObject.getString("launchDate"));
                        }
                        if (!jsonObject.isNull("launchSize")) {
                            entity.setLaunchSize(jsonObject.getString("launchSize"));
                        }
                        if (!jsonObject.isNull("launchPrice")) {
                            entity.setLaunchPrice(jsonObject.getString("launchPrice"));
                        }
                        if (!jsonObject.isNull("fundSizeDate")) {
                            entity.setFundSizeDate(jsonObject.getString("fundSizeDate"));
                        }
                        if (!jsonObject.isNull("managementFee")) {
                            double l = jsonObject.getDouble("managementFee");
                            BigDecimal b = new BigDecimal(l);
                            entity.setManagementFee(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("custodianFee")) {
                            double l = jsonObject.getDouble("custodianFee");
                            BigDecimal b = new BigDecimal(l);
                            entity.setCustodianFee(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("investmentObjective")) {
                            entity.setInvestmentObjective(jsonObject.getString("investmentObjective"));
                        }
                        if (!jsonObject.isNull("investmentScope")) {
                            entity.setInvestmentScope(jsonObject.getString("investmentScope"));
                        }
                        if (!jsonObject.isNull("investmentStrategy")) {
                            entity.setInvestmentStrategy(jsonObject.getString("investmentStrategy"));
                        }
                        if (!jsonObject.isNull("riskDisclosure")) {
                            entity.setRiskDisclosure(jsonObject.getString("riskDisclosure"));
                        }
                        if (!jsonObject.isNull("ipoStartDate")) {
                            entity.setIpoStartDate(jsonObject.getString("ipoStartDate"));
                        }
                        if (!jsonObject.isNull("ipoEndDate")) {
                            entity.setIpoEndDate(jsonObject.getString("ipoEndDate"));
                        }
                        if (!jsonObject.isNull("isRspEnable")) {
                            entity.setIsRspEnable(jsonObject.getString("isRspEnable"));
                        }
                        if (!jsonObject.isNull("isSellEnable")) {
                            entity.setIsSellEnable(jsonObject.getString("isSellEnable"));
                        }
                        if (!jsonObject.isNull("isSwitchEnable")) {
                            entity.setIsSwitchEnable(jsonObject.getString("isSwitchEnable"));
                        }
                        if (!jsonObject.isNull("maxBuyAmount")) {
                            double l = jsonObject.getDouble("maxBuyAmount");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMaxBuyAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("maxIpoAmount")) {
                            double l = jsonObject.getDouble("maxIpoAmount");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMaxIpoAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("maxRspAmount")) {
                            double l = jsonObject.getDouble("maxRspAmount");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMaxRspAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minInitialBuyAmount")) {
                            double l = jsonObject.getDouble("minInitialBuyAmount");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinInitialBuyAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minInitialIpoAmount")) {
                            double l = jsonObject.getDouble("minInitialIpoAmount");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinInitialIpoAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minSubseqBuyAmout")) {
                            double l = jsonObject.getDouble("minSubseqBuyAmout");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinSubseqBuyAmout(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minSubseqIpoAmout")) {
                            double l = jsonObject.getDouble("minSubseqIpoAmout");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinSubseqIpoAmout(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minRspAmount")) {
                            double l = jsonObject.getDouble("minRspAmount");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinRspAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minRedemptionUnit")) {
                            double l = jsonObject.getDouble("minRedemptionUnit");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinRedemptionUnit(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("minRetainUnit")) {
                            double l = jsonObject.getDouble("minRetainUnit");
                            BigDecimal b = new BigDecimal(l);
                            entity.setMinRetainUnit(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        }
                        if (!jsonObject.isNull("buyConfirmLag")) {
                            entity.setBuyConfirmLag(jsonObject.getString("buyConfirmLag"));
                        }
                        if (!jsonObject.isNull("redemptionSettleLag")) {
                            entity.setRedemptionSettleLag(jsonObject.getString("redemptionSettleLag"));
                        }
                        list.add(entity);
                    }
                }
            }
        }
        msg.setData(list);
        return msg;
    }
}
